﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using GdHotel.Data.Interfaces;
using GdHotel.Data.Repositories;
using GdHotel.Web.Attributes;
using GdHotel.Web.Models;
using UniqueTechnologies.Attributes;
using UniqueTechnologies.Data.Interfaces;

namespace GdHotel.Web.Controllers
{
    [LayoutSupport]
    [LanguageSupport]
    public class NewsController : BaseUiController
    {
        private readonly string newsKey = "news";

        public override ILanguagesRepository LanguagesRepository { get; set; }
        public override INotesRepository NotesRepository { get; set; }
        public override IMainMenuItemsRepository MainMenuItemsRepository { get; set; }
        public override IAdditionalMenuItemsRepository AdditionalMenuItemsRepository { get; set; }
        public INewsRepository NewsRepository { get; set; }
        public IGalleriesRepository GalleriesRepository { get; set; }
        public ISideBlocksCustomPagesRepository SideBlocksCustomPagesRepository { get; set; }

        public NewsController(
            ILanguagesRepository languagesRepository, 
            INotesRepository notesRepository, 
            IMainMenuItemsRepository mainMenuItemsRepository, 
            IAdditionalMenuItemsRepository additionalMenuItemsRepository, 
            INewsRepository newsRepository,
            IGalleriesRepository galleriesRepository,
            ISideBlocksCustomPagesRepository sideBlocksCustomPagesRepository)
        {
            LanguagesRepository = languagesRepository;
            NotesRepository = notesRepository;
            MainMenuItemsRepository = mainMenuItemsRepository;
            AdditionalMenuItemsRepository = additionalMenuItemsRepository;
            NewsRepository = newsRepository;
            GalleriesRepository = galleriesRepository;
            SideBlocksCustomPagesRepository = sideBlocksCustomPagesRepository;
        }

        //
        // GET: /News/

        public ActionResult Index()
        {
            var latestNews = NewsRepository.GetLatestNewsByLang(Language);
            var gallery = GalleriesRepository.FindAllByKey("common").FirstOrDefault();
            var sideBlocks = SideBlocksCustomPagesRepository.FindAllByLang(Language).Where(b => b.Key.Equals(newsKey, StringComparison.InvariantCultureIgnoreCase));
            var model = new NewsModel {News = latestNews, Gallery = gallery, SideBlocks = sideBlocks};
            return View(model);
        }

        //
        // GET: /News/Show/4

        public ActionResult Show(Int32 id)
        {
            var singleNews = NewsRepository.GetById(id);
            var latestNews = NewsRepository.GetLatestNewsByLang(Language, 3);
            var gallery = GalleriesRepository.FindAllByKey("common").FirstOrDefault();
            var model = new NewsModel { News = latestNews, SingleNews = singleNews , Gallery = gallery };
            return View(model);
        }

    }
}
